package com.example.administrator.service;

import android.app.AlarmManager;
import android.app.PendingIntent;
import android.content.Intent;
import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;
import android.view.View;
import android.widget.Toast;

import java.util.Calendar;

public class AlarmService extends AppCompatActivity {

    private static AlarmService appRef = null;
    boolean k = false;


    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);
        appRef = this;
    }

    /*获取app路径*/
    public static AlarmService getApp(){
        return appRef;
    }

    /*更改标题*/
    public void btEvent(String data){
        setTitle(data);
    }

    /*闹钟按钮点击事件*/
    public void startAlarm(View view) {
        setTitle("Please waiting..");
        Intent intent1 = new Intent(AlarmService.this,AlarmReceiver.class);
        PendingIntent p_intent = PendingIntent.getBroadcast(AlarmService.this,0,intent1,0);

        Calendar calendar = Calendar.getInstance();
        calendar.setTimeInMillis(System.currentTimeMillis());
        calendar.add(Calendar.SECOND,3);    //+3秒（如：calendar.add(Calendar.MINUTE, -60)表示减1小时）

        AlarmManager ag = (AlarmManager) getSystemService(ALARM_SERVICE);
        ag.set(AlarmManager.RTC_WAKEUP,calendar.getTimeInMillis(),p_intent);
    }


    /*播放器按钮点击事件*/
    public void starPlayer(View view) {
        Intent intent2 = new Intent(AlarmService.this,MusicPlayer.class);
        startActivity(intent2);
    }
}
